package com.liunian.subject.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.liunian.subject.common.entity.PageInfo;
import com.liunian.subject.common.enums.IsDeletedFlagEnum;
import com.liunian.subject.infra.basic.entity.SubjectInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

@Data
@ApiModel(value = "题目信息BO")
public class SubjectInfoBO extends PageInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "题目名称")
    private String subjectName;

    @ApiModelProperty(value = "题目难度")
    private Integer subjectDifficult;

    @ApiModelProperty(value = "出题人")
    private String settleName;

    @ApiModelProperty(value = "题目类型 1单选 2多选 3判断 4简答")
    private Integer subjectType;

    @ApiModelProperty(value = "分数")
    private Integer subjectScore;

    @ApiModelProperty(value = "解析")
    private String subjectParse;

    @ApiModelProperty(value = "题目答案")
    private String subjectAnswer;

    @ApiModelProperty(value = "题目类别id列表")
    private List<Long> categoryIds;

    @ApiModelProperty(value = "题目标签id列表")
    private List<Long> labelIds;

    @ApiModelProperty(value = "答案信息列表")
    private List<SubjectAnswerBO> optionList;

    @Data
    public static class SubjectAnswerBO {
        @ApiModelProperty(value = "答案选项标识")
        private Integer optionType;

        @ApiModelProperty(value = "选项内容")
        private String optionContent;

        @ApiModelProperty(value = "是否正确")
        private Integer isCorrect;
    }

    public SubjectInfo boToEntity() {
        SubjectInfo entity = new SubjectInfo();
        entity.setId(this.id);
        entity.setSubjectName(this.subjectName);
        entity.setSubjectDifficult(this.subjectDifficult);
        entity.setSettleName(this.settleName);
        entity.setSubjectType(this.subjectType);
        entity.setSubjectScore(this.subjectScore);
        entity.setSubjectParse(this.subjectParse);
        entity.setCreatedAt(LocalDateTime.now());
        entity.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        entity.setCategoryId(this.categoryId);
        entity.setLabelId(this.labelId);
        return entity;
    }

    public SubjectInfoBO entityToBo(SubjectInfo entity) {
        SubjectInfoBO bo = new SubjectInfoBO();
        bo.setId(entity.getId());
        bo.setSubjectName(entity.getSubjectName());
        bo.setSubjectDifficult(entity.getSubjectDifficult());
        bo.setSettleName(entity.getSettleName());
        bo.setSubjectAnswer(entity.getSubjectName());
        bo.setSubjectType(entity.getSubjectType());
        bo.setSubjectScore(entity.getSubjectScore());
        bo.setSubjectParse(entity.getSubjectParse());
        return bo;
    }

    @ApiModelProperty(value = "类别id")
    private Long categoryId;

    @ApiModelProperty(value = "标签id")
    private Long labelId;

    @ApiModelProperty(value = "标签名列表")
    private List<String> labelNames;

}